package com.sugar.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 *
 * 反射获取成员方法并运行
 * @author felix
 * @date 2025/2/10 16:27
 */
public class ReflectDemo6 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Student s = new Student();
        Class<?> clazz = Class.forName("com.sugar.reflection.Student");

        Method eat = clazz.getMethod("eat", String.class);
        String res = (String) eat.invoke(s, "饺子");
        System.out.println(res);
    }
}
